<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="minimum-scale=1.0, width=device-width, maximum-scale=1.0, user-scalable=no"/>
    <meta charset="utf-8">
    <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
    <title>Children</title>
</head>
<body>
<div id="react-container"></div>
  <script type="text/babel">

      const { Children } = React
      const { render } = ReactDOM

      const findChild = (children, child) =>
        Children.toArray(children)
                .filter(c => c.type === child )[0]

      const WhenTruthy = ({children}) =>
          Children.only(children)

      const WhenFalsy = ({children}) =>
          Children.only(children)

      const Display = ({ ifTruthy=true, children }) =>
          (ifTruthy) ?
              findChild(children, WhenTruthy) :
              findChild(children, WhenFalsy)

      const age = 19

      render(
          <Display ifTruthy={age >= 21}>
              <WhenTruthy>
                 <h1>You can Enter</h1>
              </WhenTruthy>
              <WhenFalsy>
                 <h1>Beat it Kid</h1>
              </WhenFalsy>
          </Display>,
          document.getElementById('react-container')
      )

  </script>
</body>
</html>
